/**
 *  Model1
 *  Author: hakute
 *  Description: 
 */

model Model1

global {
	/** Insert the global definitions, variables and actions here */
	file shape_file_bounds <- file('../includes/Batiment/Bounds.shp');
	file shape_file_obtacles <- file('../includes/Batiment/Obtacles.shp');
	file shape_file_areas <- file('../includes/Batiment/Area.shp');
	file shape_file_safe_areas <- file('../includes/Batiment/Save_place.shp');
	file shape_file_fired_areas <- file('../includes/Batiment/Fired_Areas.shp');
	file shape_file_sonneur <- file('../includes/Batiment/Sonneur.shp');
	list list_fired_areas of: fired_areas;
	list list_areas of:areas;
	list list_obtacles of:obtacles;
	
	init {
		create obtacles from: shape_file_obtacles ;
		create areas from: shape_file_areas ;
		create safe_areas from: shape_file_safe_areas;
		create fired_areas from: shape_file_fired_areas;
		create sonneur from: shape_file_sonneur;
		set list_fired_areas <-fired_areas as list;
		set list_areas <-areas as list;
		set list_obtacles <-obtacles as list;
		create evacuees_normal number:20{
			set location <- any_point_in (one_of (areas));
		}
		create feux number: 10{
			set location <- any_point_in (one_of (list_fired_areas));
		}
	}
}

environment bounds: shape_file_bounds torus:false;

entities {
	/** Insert here the definition of the species of agents */
	
	//office
	species obtacles {
		string type; 
		rgb color <- rgb([155,0,0])  ;
		aspect base {
			draw geometry: shape color: color ;
		}
	}
	species areas  {
		rgb color <- rgb('white') ;
		aspect base {
			draw geometry: shape color: color ;
		}
	}
	species safe_areas {
		rgb color <- rgb('white') ;
		aspect base {
			draw geometry: shape color: color ;
		}
	}
	species fired_areas {
		rgb color <- rgb('white') ;
		aspect base {
			draw geometry: shape color: color ;
		}
	}
	
	//evacuees
	species evacuees_normal skills : [ moving, situated ] control : fsm{
		float taile <-30.0;
		rgb color <-rgb([0,rnd(200)+55,0]);
		int puissance <-2000;
		int niveauEffectue <-3;
		float vitesseMax<-50.0;
		float vitesseActuelle <-30.0;
		int direction <-180;
		float range_emergent<-50.0;
		float range_voir<-100.0;
		float range_entendre<-200.0;
		safe_areas but <-nil;
		
		reflex find_path when: but = nil{
			do action: move_normal;
			let areas_emergents_voir <- ( (self neighbours_at (range_voir)) of_species safe_areas );
			ask areas_emergents_voir {													
				set myself.but <- self;
			}			
		}
		
		reflex gotoEmergentAreas when: ( but != nil ) {			
				do action: gotoEmergentAreas;																					
				}		
			
		action move_normal {
			do wander speed: vitesseActuelle  amplitude: direction bounds: areas ;
		}
		action gotoEmergentAreas{
 			if ( but != nil ) {
 				do goto target: but.location speed: vitesseMax;
 				do action: die;
 				}	
		}
		
		aspect base {
			draw shape:circle size:taile color: color ;
			draw shape: circle color: rgb('red') size: range_emergent*2+taile empty: true;
			draw shape: circle color: rgb('orange') size: range_voir*2+taile empty: true;
			draw shape: circle color: rgb('green') size: range_entendre*2+taile empty: true;
		}
		
	}
	
	//feux
	species feux skills : [ situated , visible ] control : fsm{
		rgb color<- rgb([rnd(200)+55,0,0]);
		float taile <-30.0;
		float rayon_effectuer <-20.0;
		float vitesse_propagation <-5.0;
		float vitesse_creer <-10.0;
	
	aspect base {
			draw shape:circle size:taile color: color ;
			}
		}
	
	//fumme
	species fumme skills : [ moving , visible ] control : fsm{
		rgb color<- rgb([rnd(200)+55,0,0]);
		float taile <-30.0;
		float vitesse_deplacer <-10.0;
	
	aspect base {
			draw shape:circle size:taile color: color ;
			}
		}
	
	// sonneur	
	species sonneur skills : [ situated , visible ] control : fsm{
		rgb color<- rgb('blue');
		float rayon_detection <-30.0;
		int duree <-30;
	
	aspect base {
			draw geometry: shape color: color ;
			}
		}
		
	
}

experiment Model1 type: gui {
	/** Insert here the definition of the input and output of the model */
	output {
		inspect name: 'Agent' type : agent ; 
		inspect name: 'Species' type : species ;
		display super_marcher refresh_every: 1 {
			species obtacles aspect: base ;
			species evacuees_normal aspect: base;
			species feux aspect: base;
			species sonneur aspect: base;
		}
	}
}